package cn.hxzy.service;


import cn.hxzy.dao.WorkDao;
import cn.hxzy.entity.Work;
import cn.hxzy.entity.vo.PageObj;

import java.sql.SQLException;
import java.util.List;

public class WorkService {
    WorkDao workDao = new WorkDao();

    public List<Work> findAll() throws Exception {
    return workDao.findAll();
    }
    public List<Work> findAll1() throws Exception {
    return workDao.findAllWithUser();
    }
    public PageObj<Work> findAll(PageObj<Work> pageObj) throws Exception {
        List<Work> all = workDao.findAll(pageObj.getPage(), pageObj.getSize());
        pageObj.setList(all);
        long count = workDao.countAll();
        pageObj.setCount(count);
        Integer size = pageObj.getSize();
        long l = count % size != 0 ? (count / size)+1 : (count / size);
        pageObj.setPageCount((int) l);
        return pageObj;
    }
    public Work findByIdWithUser(int id) throws SQLException {
        return workDao.findByIdWithUser(id);
    }
}
